<template>
  <div>
    <!--表头条件搜索  -->
    <a-form-model layout="inline" :model="tableform">
      <a-form-model-item>
          <a-input placeholder="请输入字段名" v-model="tableform.columnName"></a-input>
      </a-form-model-item>
      <a-form-model-item>
        <a-input placeholder="请输入字段描述" v-model="tableform.columnDesc"></a-input>
      </a-form-model-item>
      <a-form-model-item :wrapper-col="{ span: 12, offset: 5 }" >
        <a-button type="primary" icon="search" @click="handleSubmit">搜索</a-button>
      </a-form-model-item>
      <a-form-model-item :wrapper-col="{ span: 12, offset: 5 }">
        <a-button type="primary" icon="sync" @click="resetForm">重置</a-button>
      </a-form-model-item>
    </a-form-model>
    <br />
    <a-table :columns="columns" :data-source="data" :pagination="false">
    </a-table>
    <br />
    <!-- 分页组件 -->
    <a-pagination :show-total="(total, range) => `第${range[0]}-${range[1]}条 , 共计${total} 条记录`" v-model="currentpage" 
        :total="total" :pageSize="pageSize" @change="pageChange" />
  </div>
</template>



<script>
import { getTableInfo } from '@/api/blood/analysis'

export default {
     name:'tableInfo',
     props:['sourceTable','databaseName'],
     data(){
         return{
            tableform:{},
            pageSize:10,
            currentpage:1,
            total:0,
            data:[],
            columns:[
                {title:'库名称',dataIndex:'databaseName',key:'databaseName'},
                {title:'表名称',dataIndex:'tableName',key:'tabelName'},
                {title:'字段名称',dataIndex:'columnName',key:'columnName'},
                {title:'数据格式',dataIndex:'dataType',key:'dataType'},
                {title:'字段描述',dataIndex:'columnDesc',key:'columnDesc'}
            ],
         }
     },
     created(){
        this.getTableInfoList();
     },
     methods:{
        getTableInfoList(){
            getTableInfo(this.sourceTable,this.databaseName,this.tableform,this.currentpage,this.pageSize).then(res=>{
                if(res.code==200){
                    this.data=res.result.tableInfos;
                    this.total=res.result.total
                }
            })
        },

        pageChange(){
            getTableInfo(this.sourceTable,this.databaseName,this.tableform,this.currentpage,this.pageSize).then(res=>{
                if(res.code==200){
                    this.data=res.result.tableInfos;
                    this.total=res.result.total
                }
            })
        },

        handleSubmit(){
            getTableInfo(this.sourceTable,this.databaseName,this.tableform,1,this.pageSize).then(res=>{
                if(res.code==200){
                    this.data=res.result.tableInfos;
                    this.total=res.result.total
                }
            })
        },

        resetForm(){
            this.tableform={},
            getTableInfo(this.sourceTable,this.databaseName,this.tableform,1,this.pageSize).then(res=>{
                if(res.code==200){
                    this.data=res.result.tableInfos;
                    this.total=res.result.total
                }
            })
        }

     }
}
</script>

<style>

</style>